//Bubble sort

# include <iostream.h>
# include <conio.h>

class BubbleSort {
  int size, temp, i, j;
  int a[100];
public:
  void get();
  void sortAsc();
  void sortDesc();
  void display();
};

void BubbleSort::get() {
  cout << "Enter the size of array: ";
  cin >> size;
  for(i = 0; i < size; i++) {
    cout << "Enter arry element no." << i+1 << ": ";
    cin >> a[i];
  }
}

void BubbleSort::sortAsc() {
  for(i = 0; i < size; i++) {
    for(j = 0; j < size; j++) {
      if(a[i] < a[j]) {
	temp = a[i];
	a[i] = a[j];
	a[j] = temp;
      }
    }
  }
}

void BubbleSort::sortDesc() {
  for(i = 0; i < size; i++) {
    for(j = 0; j < size; j++) {
      if(a[i] > a[j]) {
	temp = a[i];
	a[i] = a[j];
	a[j] = temp;
      }
    }
  }
}

void BubbleSort::display() {
  cout << "\nNow the Array is: [ ";
  for(i = 0; i < size; i++) {
    cout << a[i] << " ";
  }
  cout << "]";
}

void main() {
  clrscr();
  BubbleSort bs;
  bs.get();
  bs.display();
  cout << "\n\nSorting in ascending order...\n";
  bs.sortAsc();
  bs.display();
  cout << "\n\nSorting in descending order...\n";
  bs.sortDesc();
  bs.display();
  getch();
}